package com.hdoit.ares.logical.share.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.hdoit.ares.logical.share.dao.IShareInfoDao;
import com.hdoit.ares.logical.share.model.ShareInfo;
import com.hdoit.ares.logical.share.model.ViewTime;
import com.hdoit.ares.logical.share.service.IShareInfoService;
import com.hdoit.ares.logical.share.service.IViewTimeService;
import com.hdoit.ares.logical.viewmodel.share.ShareInfoSearch;
import com.tennetcn.common.dao.base.impl.SuperService;
import com.tennetcn.common.enums.ModelStatus;
import com.tennetcn.common.message.PagerModel;
import com.tennetcn.common.utils.CommonUtils;
/**
 * @author      wangxuexue
 * @email       
 * @createtime  2017年11月18日 12:00:48
 * @comment
 */
@Component
public class ShareInfoServiceImpl extends SuperService<ShareInfo> implements IShareInfoService{

    private IViewTimeService viewTimeService;
	
	public IViewTimeService getViewTimesService() {
		return viewTimeService;
	}

	@Resource
	public void setViewTimesService(IViewTimeService viewTimeService) {
		this.viewTimeService = viewTimeService;
	}
	
	private IShareInfoDao shareInfoDao;
	
	public IShareInfoDao getShareInfoDao() {
		return shareInfoDao;
	}

	@Resource
	public void setShareInfoDao(IShareInfoDao shareInfoDao) {
		this.shareInfoDao = shareInfoDao;
	}

	@Override
	public List<ShareInfo> queryLimitInfo(String infoType) {
		
		return shareInfoDao.queryLimitInfo(infoType);
	}

	@Override
	public List<ShareInfo> queryAllInfo(String infoType) {
		
		return shareInfoDao.queryAllInfo(infoType);
	}

	@Override
	public ShareInfo queryInfoDetails(String id) {
		
		return shareInfoDao.queryInfoDetails(id);
	}

	@Override
	public List<ShareInfo> queryOtherInfo(String infoType, String id) {
		
		return shareInfoDao.queryOtherInfo(infoType, id);
	}

	@Override
	public int queryShareInfoCount(ShareInfoSearch shareInfoSearch) {
		
		return shareInfoDao.queryShareInfoCount(shareInfoSearch);
	}

	@Override
	public List<ShareInfo> queryShareInfoList(ShareInfoSearch shareInfoSearch,PagerModel pagerModel) {
		
		return shareInfoDao.queryShareInfoList(shareInfoSearch, pagerModel);
	}

	@Override
	public ShareInfo queryShareInfoModel(String key) {
	
		return shareInfoDao.queryShareInfoModel(key);
	}

	@Override
	public boolean applyChange(ShareInfo shareInfo) {
		if(super.applyChange(shareInfo)){
			
			if(ModelStatus.add.equals(shareInfo.getModelStatus())){
				
					ViewTime viewTime = new ViewTime();
					viewTime.setId(CommonUtils.getKeyId());
					viewTime.setShareid(shareInfo.getId());
					viewTime.setType("info");
					viewTime.setViewtimes(0);
					viewTime.setDeleteMark(shareInfo.getDeleteMark());
					return viewTimeService.addModel(viewTime);	
			}
			
			return true;
	}
		
		return false;
	}

	@Override
	public int updatePicById(String id) {
		
		return shareInfoDao.updatePicById(id);
	}

	@Override
	public int updateSmallPicById(String id) {
		
		return shareInfoDao.updateSmallPicById(id);
	}
}